<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>ajax 请求</title>
</head>
<body>
<script type="text/javascript">
    function sendRequest() {
        var idValue = document.getElementById("id").value;
        if (!idValue) {
            alert("请输入序号！");
            return;
        }

        var encodedId = encodeURIComponent(idValue); // 对 ID 进行 URL 编码

        var xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
            if (this.readyState == 4) {
                if (this.status == 200) {
                    document.getElementById("mySpan").innerHTML = this.responseText;
                } else {
                    alert("请求失败，状态码：" + this.status);
                }
            }
        };

        // 正确的 URL 格式，假设你的后端期望的是这样的路径
        xhr.open("GET", "/ssm/users/" + encodedId, true);
        xhr.send();
    }
</script>
序号：<input type="text" id="id">
<br>
<button onclick="sendRequest()">查询</button>
<br>
<span id="mySpan"></span>

</body>
</html>